#!/usr/bin/python
import pygame
import GIFImage
import os

if __name__ == "__main__":
	pygame.init()
	
	path_novice = os.path.join( "gif", "chars", "novice", "novice_frontal_walk.gif" )
	path_poring = os.path.join( "gif", "monsters", "poring", "poring_standing.gif" )
	fondo = pygame.image.load ("fondo.png")
	novice = GIFImage.GIFImage( path_novice )
	poring = GIFImage.GIFImage( path_poring )
	
	coords = [380,0]
	posfinal = [380, 0]
	velocidad = [2,2]
	
	clock = pygame.time.Clock()
	
	pantalla = pygame.display.set_mode( (fondo.get_width(), fondo.get_height() ) )
	
	while not pygame.key.get_pressed() [pygame.K_ESCAPE]:
		pantalla.blit( fondo, (0,0) )
		novice.render( pantalla, (coords[0], coords[1] + poring.get_height() - 8) )
		poring.render( pantalla, coords )
		
		pygame.display.flip()
		
		if coords[0] != posfinal[0]:
			coords[0] += ( posfinal[0] - coords[0] ) / abs( posfinal[0] - coords[0] ) * velocidad[0]
		if coords[1] != posfinal[1]:
			coords[1] += ( posfinal[1] - coords[1] ) / abs( posfinal[1] - coords[1] ) * velocidad[1]
		
		if coords[0] < 0 or coords[0] + novice.get_width() > pantalla.get_width():
			velocidad[0] = -velocidad[0]
		elif coords[1] < 0 or coords[1] + novice.get_height() + poring.get_height() > pantalla.get_height():
			velocidad[1] = -velocidad[1]
			novice.reverse()
			
		for event in pygame.event.get():
			if event.type == pygame.locals.QUIT:
				pygame.quit()
			elif event.type == pygame.locals.MOUSEBUTTONDOWN:
				posfinal[0] = event.pos[0]
				posfinal[1] = event.pos[1]
			
		clock.tick( 60 )
